<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>工单操作</title>
    <link rel="stylesheet" href="/resources/layui/css/layui.css" media="all">
    <script src="/resources/layui/layui.js"></script>
    <link rel="stylesheet" href="/resources/layui/css/layui.css" media="all">
    <script src="/resources/layui/layui.js"></script>
    <link rel="stylesheet" href="/resources/css/bootstrap.min.css"/>
    <script src="/resources/js/jquery.min.js"></script>
    <script src="/resources/js/bootstrap.min.js"></script>
    <script src="/resources/layui/css/layui.css"></script>
</head>
<body>

<table id="demo" lay-filter="test"></table>
</body>
</html>

<script>
    var table,layer;
    layui.use('table', function(){
       table = layui.table;
        layer=layui.layer;
        //第一个实例
        table.render({
            elem: '#demo'
            ,url: 'http://localhost:8888/yeweu/list' //数据接口
            ,page: true //开启分页
            ,toolbar:"#toolbarDemo"
            ,cols: [[ //表头
                {field: 'id', title: '所属业务通知单'}
                ,{field: 'type', title: '类型',templet:function (d) {
                        if (d.type==null||d.type==0){
                            return '自动'
                        }else if(d.type==1){
                            return '手动'
                        }
                    }}
                ,{field: 'zhuangtai', title: '取件状态',templet:function (d) {
                        if (d.zhuangtai==null||d.zhuangtai==0) {
                            return '已取件'
                        }else if (d.zhuangtai==1){
                            return '未取件'
                        }
                    }}
                ,{field: 'qDeta', title: '生成时间'}
                ,{field: 'zhuiCount', title: '追单次数'}
                ,{field: 'name', title: '取派员',templet:function(d){
                    return d.qvpai.name;
                }}
                ,{title:'操作',toolbar: '#barDemo'}
            ]]
        });
        //监听行内的工具条
        table.on('tool(test)',function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            switch(layEvent){
                case "edit":
                    $.get('Amend.html',function (s) {
                        layer.open({
                            title: '修改信息',
                            type:1,
                            anim:2,
                            skin:'layui-layer-molv',
                            area:'75%',
                            content:s,
                            maxmin:true,
                            btn : ['确定','取消'],
                            success:function(){
                                $("#did").val(data.id);
                                $("#lianxi").val(data.phone);
                                $("#kefu").val(data.khName);
                                $("#shou").val(data.shName);
                                $("#daod").val(data.daoda);
                                $("#shij").val(data.qDeta);
                                $("#beizhu").val(data.beizhu);
                                $("#minci").val(data.hpName);
                                $("#dizhi").val(data.address);
                                $("#shuli").val(data.hpCount);
                                $("#zongl").val(data.hpZhongliang);
                            },
                            yes : function (index) {
                                var str= $("#add_user_form").serialize();
                                $.get("http://localhost:8888/yeweu/updates",str,function(d){
                                    table.reload("demo");
                                    layer.close(index);
                                    layer.close("添加成功");
                                });
                            }
                        });
                    });
                    break;
                case "zui":
                    $.get('ZhuiDan.html',function (s) {
                        layer.open({
                            title: '追点信息',
                            type:1,
                            anim:2,
                            skin:'layui-layer-molv',
                            area:'50%',
                            content:s,
                            maxmin:true,
                            btn : ['确定','取消'],
                            success:function(){
                                $("#zid").val(data.id);
                            },
                            yes : function (index) {
                                var str= $("#zuidan").serialize();
                                $.get("http://localhost:8888/yeweu/zhuendans",str,function(d){

                                    layer.close(index);
                                    layer.close("添加成功");
                                    table.reload("demo");
                                });
                            }
                        });
                    });
                    break;

                case "dels":
                    table.on('tool(test)',function (obj) {
                        var data = obj.data;
                        var layEvent = obj.event;
                        if (layEvent==='dels'){//删除
                            layer.confirm('真的删除行么', function(index){
                                layer.close(index);
                                $.post("http://localhost:8888/yeweu/delete",{id:data.id},function(d){
                                    layer.close(index);
                                    layer.close("删除成功");
                                    table.reload("demo");
                                });
                            });
                        }
                    })

                    break;
            }
        });

    });
</script>


<script type="text/html" id="barDemo">
    <a href="javascript:void(0);" lay-event="zui"><i class="layui-icon layui-icon-add-circle"></i></a>
    <a href="javascript:void(0);" lay-event="edit"><i class="layui-icon layui-icon-edit"></i></a>
</script>